package com.xinliu.fastchat.controller;


import com.xinliu.fastchat.context.BaseContext;
import com.xinliu.fastchat.domain.core.R;
import com.xinliu.fastchat.domain.dto.FriendRequestDto;
import com.xinliu.fastchat.domain.vo.FriendRequestVo;
import com.xinliu.fastchat.service.IFriendRequestService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 心流
 * @since 2025-10-01
 */
@RestController
@RequestMapping("/fc-friend-request")
@RequiredArgsConstructor
@Slf4j
public class FriendRequestController {

    private final IFriendRequestService iFriendRequestService;

    //好友申请
    @PostMapping("/request")
    public R request(@RequestBody FriendRequestDto friendRequestDto) {
        log.info("用户发起了好友申请 用户id:{}, 对象:{}", BaseContext.getId(), friendRequestDto);
        return iFriendRequestService.request(friendRequestDto);
    }

    //操作申请
    @PostMapping("/handle-request")
    public R handleRequest(Integer friendRequestId, Integer status) {
        log.info("处理了好友申请,用户id:{} 申请id:{} 结果:{}", BaseContext.getId(), friendRequestId, status);
        return iFriendRequestService.handleRequest(friendRequestId, status);
    }

    //获得请求列表
    @GetMapping("/request-list")
    public R requestList() {
        log.info("获取了好友申请列表,用户id:{}", BaseContext.getId());
        List<FriendRequestVo> list = iFriendRequestService.requestList(BaseContext.getId());
        return R.ok(list);
    }

}
